package components.score;

import java.awt.Color;
import java.awt.Font;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Label;

public class ScoreLabel extends GameComponent {
	private int score;
	private String showableText;
	private boolean changed;
	private Label label;
	
	public ScoreLabel(int initialScore){
		this.score = initialScore;
		this.showableText = "Score : ";
		this.changed = false;
		this.setLabel(new Label(new Font(Font.SERIF, Font.BOLD, 20), Color.WHITE, this.getShowableText()));
		this.setAppearance(this.label);
	}
	
	public void add(int sc){
		this.setScore(this.getScore() + sc);
		this.changed = true;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public int getScore() {
		return score;
	}

	public void setShowableText(String showableText) {
		this.showableText = showableText;
	}
	
	public String getShowableText() {
		return showableText + this.getScore();
	}
	public void update (DeltaState delta){
		if (this.hasChanged()){
			this.getLabel().setText(getShowableText());
			this.setAppearance(this.getLabel());
			this.setChanged(false);
		}
	}

	public void setChanged(boolean changed) {
		this.changed = changed;
	}

	public boolean hasChanged() {
		return changed;
	}

	public void setLabel(Label label) {
		this.label = label;
	}

	public Label getLabel() {
		return label;
	}
}
